/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import java.sql.*;
import java.util.Collection;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gcanu
 */
public class DAO {

    public static Collection<Departement> getLesDeps() {

        Collection<Departement> lesDeps = new TreeSet<Departement>();
        

        try {
            // Variables
            Connection con = Connect.get();
            Statement req;
            Statement req2;

            // Récupération des départements
            req = con.createStatement();
            ResultSet rs = req.executeQuery("select distinct departement from medecin");
                     
            while (rs.next()) {
                String departement = rs.getString("departement");
                Collection <Medecin> lesMeds = new TreeSet <Medecin> ();
                
                req2 = con.createStatement();
                ResultSet rs2 = req2.executeQuery("select * from medecin where departement = " + departement + "");
                while (rs2.next()) {
                    String nom = rs2.getString("nom");
                    String prenom = rs2.getString("prenom");
                    String adresse = rs2.getString("adresse");
                    String tel = rs2.getString("tel");
                    String spe = rs2.getString("specialitecomplementaire");
                    String id = rs2.getString("id");
                    lesMeds.add(new Medecin(nom, prenom, adresse, tel, spe, id));
                }
                lesDeps.add(new Departement(departement, lesMeds));
            }
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return lesDeps;
    }
}
